package com.dailyblue.java.net.udp;

import lombok.SneakyThrows;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UdpClient {
    @SneakyThrows
    public static void main(String[] args) {
        // 创建套接字 指定端口号
        DatagramSocket socket = new DatagramSocket(8888);
        System.out.println("套接字启动成功");
        // 创建接收包裹
        byte[] data = new byte[100];
        DatagramPacket packet = new DatagramPacket(data, 100);
        System.out.println("包裹创建成功!");
        // 接收
        socket.receive(packet);
        String str = new String(data, 0, packet.getLength());
        System.out.println(str);
    }
}
